<?php
class article_model extends CI_Model{
		public $model;
		function __construct(){
			$this->model='article';
		}
		
		public function get_paging2($config,$page,$value){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$PPP= ($page-1)*$config['per_page'];
				$data['info']=$this->db->query("SELECT * FROM boc_article where title like '%$value%' AND audit = 1 AND
						(cid = 2 OR cid = 3 OR cid = 4 OR cid = 5 OR cid = 6)
						ORDER BY sort_id desc limit $PPP,{$config['per_page']}")->result_array();
		
				// 				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				// 				limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			return $temp;
		}
		
		/*
		 * 图片分页（无分类，带photo）
		 */
		public function photo_page($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
											limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					$imgId=$v['photo'];
					$temp['new_con'][$k]['img']=$this->db->get_where('upload',array('id'=>$imgId))->row_array();
				}
			}
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					if(!empty($v['file'])){
						$temp['new_con'][$k]['file']=$this->db->get_where('upload',array('id'=>$v['files']))->row_array();
					}
				}
			}
			return $temp;
		}
		public function ajax_page($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					$imgId=$v['photo'];
					$temp['new_con'][$k]['img']=$this->db->get_where('upload',array('id'=>$imgId))->row_array();
					//$temp['new_con'][$k]['img']=str_replace("/thumbnail/","/",UPLOAD_URL.$v['thumb']);
				}
			}
			return $temp;
		}
		
		/*
		 * 图片分页（无分类，带photo）
		*/
		public function photo_book($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('ebook')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					$imgId=$v['photo'];
					$temp['new_con'][$k]['img']=$this->db->get_where('upload',array('id'=>$imgId))->row_array();
				}
			}
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					if(!empty($v['file'])){
						$temp['new_con'][$k]['file']=$this->db->get_where('upload',array('id'=>$v['files']))->row_array();
					}
				}
			}
			return $temp;
		}
		/*
		 * 招聘
		*/
		public function get_rec($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('recruit')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				$data['info']='';
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			return $temp;
		}
		
		/*
		 * 学校动态分页
		 */
		public function get_paging($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
											limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			return $temp;
		}
		
		/*
		 * 学校动态分页
		*/
		public function get_paging1($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('recruit')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			return $temp;
		}
		
		
		/*
		 * 获取详情页
		*/
		public function get_info($id,$cid){
			$query=$this->db->get_where('article',array('id'=>$id,'cid'=>$cid))->row_array();
			if(!empty($query['photo1'])){
				$query['img1']=$this->db->get_where('upload',array('id'=>$query['photo1']))->row_array();
			}
			if(!empty($query['video'])){
				$query['vid']=$this->db->get_where('upload',array('id'=>$query['video']))->row_array();
			}
			return $query;
		}
		
		 		/*
         * 新闻页面上一篇、下一篇文章、返回上一级列表
         */
        public function change_type_page($id,$cid){
          	$data['one']=$this->db->get_where($this->model,array('id'=>$id,'cid'=>$cid,'audit'=>1))->row_array();
            if(!empty($data['one'])){
            	$sortId=$data['one']['sort_id'];
            	//获取上一页的新闻
            	$data['prev']= $this->db->where(array('sort_id <'=>$sortId,'ctype'=>$data['one']['ctype'],'audit'=>1))->order_by("sort_id","desc")->get($this->model)->row_array();
            	//获取下一页的新闻
            	$data['next']= $this->db->where(array('sort_id >'=>$sortId,'ctype'=>$data['one']['ctype'],'audit'=>1))->order_by("sort_id","asc")->get($this->model)->row_array();
            	//返回上一页列表
            	$data['back']=$this->db->where(array('id'=>$id,'ctype'=>$data['one']['ctype'],'audit'=>1))->get($this->model)->row_array();
            }
            return $data;
        }
        
        /*
         * 新闻页面上一篇、下一篇文章、返回上一级列表（无分类）
        */
        public function change_page($id,$cid){
        	$data['one']=$this->db->where(array('id'=>$id,'audit'=>1))->get($this->model)->row_array();
        	//查询记录是否存在
        	if(!empty($data['one'])){
        		$data['sortId']=$data['one']['sort_id'];
        	//获取上一页的新闻
        	$data['prev']= $this->db->where(array('sort_id <'=>$data['sortId'],'cid'=>$cid,'audit'=>1))->order_by("sort_id","desc")->get($this->model)->row_array();
        	//获取下一页的新闻
        	$data['next']= $this->db->where(array('sort_id >'=>$data['sortId'],'cid'=>$cid,'audit'=>1))->order_by("sort_id","asc")->get($this->model)->row_array();
        	//返回上一页列表
        	$data['back']=$this->db->where(array('id'=>$id,'cid'=>$cid,'audit'=>1))->get($this->model)->row_array();
        	}
        	return $data;
        }     
		
		/*
		 * 获取职业资格培训tit
		 */
		public function get_tit(){
			$query=$this->db->get_where($this->model,array('audit'=>1,'cid'=>11,'ccid'=>0))->result_array();
			return $query;
		}
		
		/*
		 * 学校动态分页
		*/
		public function get_ebook_paging($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->limit($config['per_page'],($page-1)*$config['per_page'])->get('ebook')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			
			if(!empty($temp['new_con'])){
				foreach($temp['new_con'] as $k=>$v){
					if(!empty($v['files'])){
						$temp['new_con'][$k]['files']=$this->db->get_where('upload',array('id'=>$v['files']))->row_array();
					}
				}
			}
			return $temp;
		}
		
		/*
		 * 获取首页新闻推荐
		 */
		public function get_hot($cid){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'flag'=>1,'cid'=>$cid))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
		
		public function get_list($cid){
			//1.先判断有多个年
			$year=$this->db->query("SELECT YEAR(FROM_UNIXTIME(timeline)) as year FROM boc_article where cid = 69 AND audit = 1 GROUP BY YEAR(FROM_UNIXTIME(timeline)) ORDER BY year desc ")->result_array();
			//2.循环取出各个年下面的数据
			$data=array();
			foreach ($year as $k=>$item){
				$data[$item['year']]=$this->db->query("SELECT * FROM boc_article where cid = 69 AND audit = 1 AND YEAR(FROM_UNIXTIME(timeline)) = ".$item['year'])->result_array();
			}
			if(!empty($data)){
				foreach($data as $k=>$v){
					if(!empty($v['photo'])){
						$data[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $data;
		}
		
		/*
		 * 产品中心
		 */
		public function get_news_list($id,$cid){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>$cid,'ctype'=>$id))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
		
		/*
		 * 新闻中心
		 */
		public function get_sett(){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>14))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
		
		/*
		 * 分页显示-----展览
		*/
		public function news_page($config,$id,$where,$page=1){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				$temp['new_con']=$data['info'];
			}else{
				return false;
			}
			$temp['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			foreach($temp['new_con'] as $k=>$v){
				if(!empty($v['photo'])):
				$imgId=$v['photo'];
				$temp['new_con'][$k]['img']=$this->db->get_where('upload',array('id'=>$imgId))->row_array();
				endif;
				if(!empty($v['video'])):
				$vidId=$v['video'];
				$temp['new_con'][$k]['video']=$this->db->get_where('upload',array('id'=>$vidId))->row_array();
				endif;
			}
			return $temp;
		}
		
		/*
		 * 学术的前几个
		 */
		public function get_first($cid){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>$cid))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
		
		/*
		 * 视频的前几个
		 */
		public function get_type_first($type){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>21,'ctype'=>$type))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
					if(!empty($v['video'])){
						$query[$k]['vid']=$this->db->get_where('upload',array('id'=>$v['video']))->row_array();
					}
				}
			}
			return $query;
		}
		
		/*
		 * 馆藏前几个
		*/
		public function get_type_gc($type){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>16,'ctype'=>$type))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
		
		/*
		 * 展览
		 */
		public function get_type_zl($type){
			$query=$this->db->order_by('sort_id','desc')->get_where($this->model,array('audit'=>1,'cid'=>11,'ctype'=>$type))->result_array();
			if(!empty($query)){
				foreach($query as $k=>$v){
					if(!empty($v['photo'])){
						$query[$k]['img']=$this->db->get_where('upload',array('id'=>$v['photo']))->row_array();
					}
				}
			}
			return $query;
		}
	
		
		/*
		 * 学校动态分页
		*/
		public function s_page($config,$page=1,$where){
			$this->load->library('pagination');//加载分页函数类
			$this->pagination->initialize($config);//初始化分页类
			$pagelink = $this->pagination->create_links();//创建分页链接
			if($config['total_rows']>0){
				//取出当前页的数据
				$data['info']=$this->db->where($where)->order_by("sort_id","desc")->
				limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
				//循环过滤$data['info']中的数据
			}else{
				return false;
			}
			$data['pagelink'] = $pagelink;//将分页链接保存到$data数组
			$temp['pagelink']=$data['pagelink'];//将$data数组中的分页链接
			$temp['total']=$config['total_rows'];//将当前页面新闻总条数保存到$temp中传递
			$temp['new_con']=$data['info'];
			return $temp;
		}
		
		
		
		
		
		
		
}